<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>开发</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../css/weui.css"/>
    <script src="../script/jquery-3.2.1.js"></script>
    <script src="../script/api.js"></script>
    <script src="../script/switch.js"></script>
    <style>
        .empty{ text-align: center; padding: 120px 0; }
    </style>
</head>
<!--入住拍照界面-->
<body>
   <div id="apiNode" style="text-align: center">
   <br/>
   	<img style="text-align: center;width: 200px;height: 300px;margin: auto auto;"/>
   </div> 
</body>
</html>
<script type="text/javascript">
var ywid ;//flag
var account = $api.getStorage("dl_phone");
var taxcode = "";
var hotleName = "";
apiready = function(){
	var id = getQueryString("id"); 
	taxcode = getQueryString("taxcode"); 
	hotleName =decodeURI(decodeURI(getQueryString("hotleName")));
	alert("我们将提交您的部分信息到公安后台进行认证比对");
	if(id!="" && taxcode!="" &&hotleName!=""){
		 getPicture();
		 getMsgByid(id);
		 }
	};
//旅馆支付
var LGpay;
var Yname;
//姓名
var Yidno;
//身份证号
var Ybase64;
//照片base64
//服务费
var Price = '10';
function getMsgByid(id){
	
	api.ajax({
	    url: 'http://www.scscpt.com:8520/wzrz/wzrz_getmsgbyid',
		method: 'post',
		dataType: 'text',
		header:{
	    	'Content-Type':'application/x-www-form-urlencoded;charset=utf-8'
	    },
	    data: {
	    	values:{
	            id: id
	    	}
	    }
	}, function(ret, err) {
	    if (ret) {
	    	var MSG5 = JSON.stringify(ret) ;	    	
	        liMsg(MSG5);
	    } else {
	        api.alert({ msg: JSON.stringify(err) });
	    }
	});
}
/*
var xhr = new XMLHttpRequest();
//发起根据旅客信息id获取旅客信息请求
function getMsgByid(id){
	if (xhr) {
		var uri = 'http://'+urlStr+'/Service1.asmx/wzrz_getMsgById';
	    xhr.open('POST', uri, true);
	    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	    xhr.onreadystatechange = handler2;
	    xhr.send("id="+id);
	} else {
	}
}
//获得旅客信息
function handler2(evtXHR) {
	if (xhr.readyState == 4){
    if (xhr.status == 200){
		var response = xhr.responseText;        
		liMsg(response);
    } else {
    	}
	}
	else {
	}
}
*/
//展示旅客系信息
 function liMsg(response){
   		var str = response.split("*");
        if(str[1]!="</string>"){
      	for(var i=1;i<str.length-1;i++){
      		var msg = str[i].split("|");
      		var countid = msg[0]
			var name = msg[1];
			Yname = name;
			var cardno = msg[2];
			Yidno = cardno;
			var code = msg[3];
			var gender = msg[4];
			gender = switchGender(gender);
			var birth = msg[5];
			var address = msg[6];
			var nation  = switchNation(code);
			var secNo = secCardNo(cardno);
			var box = document.getElementById("apiNode");
			var li = document.createElement("div"); 
			li.style.textAlign = "left";
			li.style.marginLeft = "20px";
			li.innerHTML = 
				'<br/><div class="weui_cells_title">身份信息：</div>'+
				'<div class="weui_cells">'+
        			'<div class="weui_cell" style="font-size:12px">'+
            			'<div class="weui_cell_bd weui_cell_primary">'+
                		'<p>'+"姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名："+name+'<br/>'+
                		"身份证号："+secNo+'<br/>'+
                		"民&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;族："+nation+'<br/>'+
                		"性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别："+gender+'<br/>'+
                		"出生日期："+birth+'<br/>'+
                		"详细住址："+address+'</p>'+
            			'</div>'+
        			'</div><br/>'+
        			'<div style="float:left;width: 100%;">'+    			
	        			'<span style="width:25%;float=left;margin:10px">'+
	        			'<button class="weui_btn weui_btn_primary" id="'+countid+'"'+
	        			'style="width: 100%;float=left;font-size:14px;background-color:#FFD700" onclick=reback(this)>返回</button>'+
	        			'</span>'+
	        			'<span style="width:25%;float=left;margin:10px">'+
	        			'<button class="weui_btn weui_btn_primary" id="'+countid+'"'+
	        			'style="width: 100%;float=left;font-size:14px" onclick=reload(this)>重新拍照</button>'+
        				'</span>'+
						'<span style="width:25%;float=left;margin:10px">'+
						'<button class="weui_btn weui_btn_primary" id="'+countid+'" value="'+name+'&'+address+'" style="background-color:'+ 
						'#18b4ed;width: 100%;font-size:14px;" onclick="upload(this)">确认入住</button>'+
	        			'</span>'+
	    			'</div>'+
        			/*
	    			'<div style="float:left;width: 100%" >'+ 
	    				'<button  id="'+countid+'" style="background-color:'+ 
						'#E1FFFF;width: 30% ;height:20px; font-size:14px;" onclick="reback(this)">返回</button>'+
	    				'<button  id="'+countid+'" style="background-color:'+ 
						'#B0C4DE;width: 30% ;height:20px; font-size:14px;" onclick="reload(this)">重新拍照</button>'+
						'<button  id="'+countid+'" style="background-color:'+ 
						'#18b4ed;width: 30% ;height:20px;font-size:14px;" onclick="upload(this)">确认</button>'+
	    			'</div>'+
	    			*/
    			'</div>';
			box.appendChild(li);  
      	}
      	
      }
    }
    //重新拍照
function reload(obj){
	getPicture();

}
//返回frame0主页面
function reback(obj){
	window.location.href="../html/frame0.html";
}

//提交信息到云平台webservice
var name;
var address;
function upload(obj){
	api.showProgress({
   				style: 'default',
   				 animationType: 'fade',
   				 title: '人像比对中...',
   				 text: '请耐心等待...',
   				 modal: false
			});
	var userInfo = obj.value.split('&');
	name = userInfo[0];
	address = userInfo[1];
	var Yid = obj.id;
	var request = Yid+"*"+Ybase64+"*"+taxcode+"*"+hotleName;	
	if(Ybase64!=""){
		api.ajax({
		    url: 'http://www.scscpt.com:8520/wzrz/insert_wzrz_t_order',
			method: 'post',
			dataType: 'text',
			header:{
		    	'Content-Type':'application/x-www-form-urlencoded;charset=utf-8'
		    },
		    data: {
		    	values:{
		            request: request
		    	}
		    }
		}, function(ret, err) {
		    if (ret) {
		    	var MSG5 = JSON.stringify(ret) ;	    	
		        var msg = MSG5.split('*');
	            flag= msg[1];
				if(flag =='Y'){			
        			api.hideProgress();
					api.alert({
						title: '审核结果',
						msg: '审核完成 ',
						buttons: ['确定']
					});
					reback();
        		}
        		else{
        			api.hideProgress();
					api.alert({
						title: '审核结果',
						msg: '审核未通过',
						buttons: ['确定']
					});
					reback();
        		}
		    } else {
		    	api.hideProgress();
		        api.alert({ msg: JSON.stringify(err) });
		    }
		});
	}
}
//企业代划直接进行人像比对
/*function duraraGo(){
	api.ajax({
		    url: 'http://www.scscpt.com:8520/wzrz/wzrz/durara2',
			method: 'post',
			dataType: 'text',
			header:{
		    	'Content-Type':'application/x-www-form-urlencoded;charset=utf-8'
		    },
			'Content-Type':'application/x-www-form-urlencoded;charset=utf-8',
		    data: {
		    	values:{
					ywid:ywid,
					taxcode:taxcode,
					price : Price
		    	}
		    }
		}, function(ret,err){
			var MSG5 = JSON.stringify(ret) ;
			var msg = MSG5.split('*');
			var flag = msg[1];
			var status;
			if(flag == 'Y'){
			 status = msg[2];
			}
			if(status !=""  && status=='S01'){
				api.hideProgress();
				api.alert({
					title: '审核结果',
					msg: '审核完成 ',
					buttons: ['确定']
				});
				reback();
			}else{
				api.hideProgress();
				api.alert({
					title: '审核结果',
					msg: '审核未通过',
					buttons: ['确定']
				});
				reback();
			}
		});
}
*/
//获取orderid
/*function getOrderId(){
	api.ajax({
		    url: 'http://www.scscpt.com:8520/wzrz/submitdd',
			method: 'post',
			dataType: 'text',
			header:{
		    	'Content-Type':'application/x-www-form-urlencoded;charset=utf-8'
		    },
			'Content-Type':'application/x-www-form-urlencoded;charset=utf-8',
		    data: {
		    	values:{
		            spdm: '2701T239901124',
					hj: '0.1',
					userid: account,
					price: '0.1',
					sl: '1'
		    	}
		    }
		}, function(ret, err) {
		    if (ret ) {
		    	var obj = JSON.parse(ret);
		    	var orderid = obj.orderid;
		    	var msg= obj.flag;
		    	if(orderid!='' && msg!='false'){
        		window.location.href="../html/order.html?orderid="+orderid+"&msg="+msg+"&name="+name+"&address="+address+"&ywid="+ywid;  }
        		else{
        		alert('提交订单失败，请返回重试');
        		}  	
		    } else {
		        api.alert({ msg: JSON.stringify(err) });
		    }
		});
}
*/
/*
function upload(obj){
	var Yid = obj.id;
	
	if(Ybase64!=""){
		//旅客身份信息id
		if (xhr) {
			var uri = 'http://'+urlStr+'/Service1.asmx/insert_wzrz_t_order';
		    xhr.open('POST', uri, true);
		    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		    xhr.onreadystatechange = handler;
		    var request = Yid+"*"+Ybase64+"*"+taxcode+"*"+hotleName;
		    xhr.send("request="+request);
		} else {
		}	
	}else{
		alert("请先进行拍照");
	}
	
}
function handler(evtXHR) {
	if (xhr.readyState == 4){
    if (xhr.status == 200){
		var response = xhr.responseText;  		
		var msg = response.split('*');
        window.location.href="../html/order.html?orderid="+msg[1];
    } else {
		
    	}
	}
	else {
	
	}
}
*/
//拍照
function getPicture() {

    api.getPicture({
        sourceType :'camera',
        encodingType :'jpg',
        mediaValue : 'pic',
        destinationType : 'base64',
        allowEdit : false,
        quality : 150,
        targetWidth : 200,
        targetHeight : 300,
        saveToPhotoAlbum : true
    }, function(ret, err) {
        if (ret) {
        	Ybase64 = ret.base64Data;
        	var ss = $api.dom("img");
        	$api.attr(ss, "src", ret.base64Data);
        }else{
        }
    });  
    
}


</script>







